package com.dkm.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "role")
public class Role {

	@Id
	private String role_id;
	private String role_name;
	
	//角色和用户多对多关系
	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name = "user_role",
			joinColumns = {@JoinColumn(name="role_id")},
			inverseJoinColumns = {@JoinColumn(name="user_id")}
	)
	private List<Users> users;
	
	//角色和模块多对多关系
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name = "role_module",
			joinColumns = {@JoinColumn(name="role_id")},
			inverseJoinColumns = {@JoinColumn(name="module_id")}
	)
	private List<Module> modules;
	
	//角色和权限多对多关系
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name = "role_permission",
			joinColumns = {@JoinColumn(name="role_id")},
			inverseJoinColumns = {@JoinColumn(name="permission_id")}
	)
	private List<Permission> permissions;
	
	public List<Users> getUsers() {
		return users;
	}
	public void setUsers(List<Users> users) {
		this.users = users;
	}
	public List<Permission> getPermissions() {
		return permissions;
	}
	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}
	public List<Module> getModules() {
		return modules;
	}
	public void setModules(List<Module> modules) {
		this.modules = modules;
	}
	public Role() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Role(String role_id, String role_name) {
		super();
		this.role_id = role_id;
		this.role_name = role_name;
	}
	public String getRole_id() {
		return role_id;
	}
	public void setRole_id(String role_id) {
		this.role_id = role_id;
	}
	public String getRole_name() {
		return role_name;
	}
	public void setRole_name(String role_name) {
		this.role_name = role_name;
	}
	@Override
	public String toString() {
		return "Role [role_id=" + role_id + ", role_name=" + role_name + "]";
	}
	
}
